<?php
class Recommend extends AppModel{
	var $name = "Recommend";
	var $order = "Recommend.id DESC";
		/*
	function getMoreFavoriteSutatues($limit){
		$this->bindModel(array('belongsTo' => array('Status')),true);
		$userModel = new User();
		$statusModel = new Status();
		$userColums = $userModel->getColumnTypes();
		foreach($userColums as $column => $type){
			$fields[] = "User.".$column;
		}
		$statusColums = $statusModel->getColumnTypes();
		foreach($statusColums as $column => $type){
			$fields[] = "Status.".$column;
		}
		
		$options = array(
			'fields' => $fields,
			'conditions' => array('Status.created_at >' => date('Y-m-d H:i:s', strtotime('-1 day'))  ),
			'group' => 'Favorite.status_id',
			'order' => 'COUNT(*) DESC',
			'joins' =>  array(
				array(
					"type" => 'LEFT',//join type
				 	"table" => 'statuses',//tablename
				 	"conditions" => 'statuses.id = Favorite.status_id' // joinのon句にあたる
				),
				array(
					"type" => 'LEFT',//join type
					"alias" => "User",
				 	"table" => 'users',//tablename
				 	"conditions" => 'User.id = statuses.user_id' // joinのon句にあたる
				)	
			),
			'limit' => $limit
		);
		return $this->find('all',$options);
	}

	function getFavCategoryRate($category){
		
	}
	function findAllByUserId($userId){
		$options = array(
				'conditions' => array(
					'Favorite.user_id' => $userId		
				)
		);
		return $this->find('all',$options);
	}

	
	function findNextByUserId($userId, $favId = 0, $count = 10){
		$options = array(
				'conditions' => array(
					'Favorite.user_id' => $userId
				), 
				'limit' => $count
		);
		if($favId != 0){
			$options['conditions']['Favorite.id <'] = $favId;
		}
		return $this->find('all',$options);
	}
	*/
	function save($data, $validate = null, $fieldList = array()){
		$this->set($data);
		if(!$this->exists()){
			$data['created_at'] = date("Y-m-d H:i:s");
		}
		return parent::save($data, $validate, $fieldList);
	}
}
?>